package com.gi.product.controller;

import com.gi.product.dto.CartDTO;
import com.gi.product.message.StreamClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by lancf on 2019/7/11.
 */
@RestController
@RefreshScope
@RequestMapping("/product/test")
public class TestConfigClientController {

    @Value("${env}")
    private String env;

    @Autowired
    private StreamClient streamClient;

    @GetMapping("/print")
    public String print() {
        return env;
    }

    /**
     * Stream发送消息
     */
    @GetMapping("/streamMsg")
    public String streamMsg() {

        String res = "now" + new Date();
        streamClient.output().send(MessageBuilder.withPayload(res).build());
        return res;
    }

    @GetMapping("/sendCartDto")
    public CartDTO sendCartDto() {

        CartDTO cartDTO = new CartDTO();
        cartDTO.setProductId("123-456");
        streamClient.output().send(MessageBuilder.withPayload(cartDTO).build());
        return cartDTO;
    }
}
